import { GBox } from "../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../com/mui/containers/globalVariable/GBoxDirection";
import { GTextFormat } from "../../../common/GTextFormat";
import { FontUtil } from "../../../common/font/FontUtil";
import { ObjCreate } from "../common/ObjCreate";
import { Vector } from "../../../../__AS3__/vec/Vector";
type int = number;
//class RollNumber
    
    export  class RollNumber /* flash.display.Sprite */
    {
        constructor(arg1: number, arg2: number, arg3: int=0, arg4: int=9)
        {
            
            this._vcGrid = new Vector.<NumberGrid>();
            this._maxSpeed = arg1;
            this._stopSpeed = arg2;
            this._currentSpeed = this._maxSpeed;
            this._minValue = arg3;
            this._maxValue = arg4;
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            var loc2=0;
            this._box = new GBox();
            this._box.direction = GBoxDirection.VERTICAL;
            this._box.verticalGap = 0;
            loc2 = this._minValue;
            while (loc2 <= this._maxValue) 
            {
                loc1 = new NumberGrid(loc2);
                this._vcGrid.push(loc1);
                this._box.addChild(loc1);
                ++loc2;
            }
            loc2 = this._minValue;
            while (loc2 <= this._maxValue) 
            {
                loc1 = new NumberGrid(loc2);
                this._vcGrid.push(loc1);
                this._box.addChild(loc1);
                ++loc2;
            }
            this._spMask = new Object /* flash.display.Sprite */();
            this._spMask.graphics.beginFill(16777215, 0.01);
            this._spMask.graphics.drawRect(0, 0, 32, 43);
            this._spMask.graphics.endFill();
            this._spMask.cacheAsBitmap = true;
            this.addChild(this._spMask);
            this.addChild(this._box);
            this._box.mask = this._spMask;
            return;
        }

        /* internal  */onEnterFrame(arg1: Object /* flash.events.Event */): void
        {
            var loc1=0;
            if (!this._isRealStop) 
            {
                if (this._isUserStop) 
                {
                    if (this._isEnd != false) 
                    {
                        this._box.y = this._box.y - this.minSpeed;
                        if (this._box.y <= this._endPosition) 
                        {
                            this._box.y = this._endPosition;
                            this.removeEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrame);
                            this.dispatchEvent(new Object /* flash.events.Event */(flash.events.Event.CLOSE));
                            return;
                        }
                    }
                    else 
                    {
                        this._currentSpeed = this._currentSpeed - this._stopSpeed;
                        this._box.y = this._box.y - this._currentSpeed;
                        if (this._currentSpeed < this.minSpeed) 
                        {
                            this._currentSpeed = this.minSpeed;
                            this._isEnd = true;
                            loc1 = Math.ceil(this._box.y / (this.GridHeight + this.VerticalGap));
                            this._endPosition = (loc1 - 1) * (this.GridHeight + this.VerticalGap);
                            this._currentNumber = Math.abs((loc1 - 1)) % this.numberLength + this._minValue;
                        }
                        this.resetY();
                    }
                }
                else 
                {
                    this._box.y = this._box.y - this._maxSpeed;
                    this.resetY();
                }
            }
            return;
        }

        /* internal  */get numberLength(): int
        {
            return this._maxValue - this._minValue + 1;
        }

        /* internal  */resetY(): void
        {
            if (this._box.y < -1 * this.GridHeight * (this.numberLength + 2) + (this.numberLength + 2) * this.VerticalGap) 
            {
                this._box.y = this._box.y + (this.GridHeight * this.numberLength + this.numberLength * this.VerticalGap);
            }
            return;
        }

        public reset(): void
        {
            this._currentNumber = 0;
            this._isRealStop = false;
            this._isUserStop = false;
            this._isEnd = false;
            this._currentSpeed = this._maxSpeed;
            this._box.y = -1 * this.GridHeight + -1 * int(Math.random() * this.GridHeight * this.numberLength);
            return;
        }

        public start(): void
        {
            if (this.hasEventListener(flash.events.Event.ENTER_FRAME)) 
            {
                return;
            }
            this.reset();
            this.addEventListener(flash.events.Event.ENTER_FRAME, this.onEnterFrame);
            return;
        }

        public stop(): void
        {
            this._isUserStop = true;
            return;
        }

        public get currentNumber(): int
        {
            return this._currentNumber;
        }

        /* internal */ /* const */minSpeed: number=0.7;

        /* internal */ /* const */GridHeight: number=43;

        /* internal */ /* const */VerticalGap: number=0;

        /* internal */ /* var */_maxSpeed: number;

        /* internal */ /* var */_stopSpeed: number;

        /* internal */ /* var */_currentSpeed: number;

        /* internal */ /* var */_box: GBox;

        /* internal */ /* var */_spMask: Object /* flash.display.Sprite */;

        /* internal */ /* var */_vcGrid: Vector.<NumberGrid>;

        /* internal */ /* var */_currentNumber: int=0;

        /* internal */ /* var */_minValue: int;

        /* internal */ /* var */_maxValue: int;

        /* internal */ /* var */_isEnd: Boolean=false;

        /* internal */ /* var */_endPosition: number;

        /* internal */ /* var */_isRealStop: Boolean=true;

        /* internal */ /* var */_isUserStop: Boolean=true;
    }
}


class NumberGrid extends flash.display.Sprite
{
    public NumberGrid(arg1: int)
    {
        super();
        this._num = arg1;
        this.init();
        return;
    }

    /* internal  */init(): void
    {
        graphics.beginFill(4294967295, 0.1);
        graphics.drawRect(0, 0, 32, 43);
        graphics.endFill();
        if (!RollNumber.textFormat) 
        {
            RollNumber.textFormat = new GTextFormat(FontUtil.songtiName, 20, 15788607);
        }
        ObjCreate.createTextField(this._num.toString(), 6, 10, 23, 30, this, RollNumber.textFormat);
        return;
    }

    public get num(): int
    {
        return this._num;
    }

    /* internal */ /* var */_num: int;

    /* internal */ static /* var */textFormat: Object /* flash.text.TextFormat */;
